package com.example.datastoreutils.screen

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.navigation3.runtime.NavEntry
import androidx.navigation3.runtime.entryProvider

data object ProductList
data class ProductDetail(val id: String)

@Composable
fun MyApp() {

    // Create a back stack, specifying the key the app should start with
    val backStack = remember { mutableStateListOf<Any>(ProductList) }

    // Supply your back stack to a NavDisplay so it can reflect changes in the UI
    // ...more on this below...

    // Push a key onto the back stack (navigate forward), the navigation library will reflect the change in state
    backStack.add(ProductDetail(id = "ABC"))

    // Pop a key off the back stack (navigate back), the navigation library will reflect the change in state
    backStack.removeLastOrNull()

    val entryProvider2 = entryProvider {
        entry<ProductList> { Text("Product List") }
        entry<ProductDetail>(
            metadata = mapOf("extraDataKey" to "extraDataValue")
        ) { key -> Text("Product ${key.id} ") }
    }


    val entryProvider = { key ->
        when (key) {
            is ProductList -> NavEntry(key) { Text("Product List") }
            is ProductDetail -> NavEntry(
                key,
                metadata = mapOf("extraDataKey" to "extraDataValue")
            ) { Text("Product ${key.id} ") }

            else -> {
                NavEntry(Unit) { Text(text = "Invalid Key: $it") }
            }
        }
    }
}
